package com.example.struts.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm {

	private String userName;
	private String password;
 

	public LoginForm(String userName) {

		this.userName = userName;

	}

	public LoginForm() {

	}

	 
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {

		ActionErrors errors = new ActionErrors();

		if (getUserName() == null || userName.trim().length() < 1) {
			errors.add("userName", new ActionMessage(
					"name.error.message"));

		}
		if (getPassword() == null || password.trim().length() < 5) {
			errors.add("password", new ActionMessage(
					"password.error.message"));

		}

		return errors;
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		 userName = null;
	}

}
